
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
#加载驱动
driver = webdriver.Chrome()
#请求网页
driver.get("https://www.baidu.com/")
time.sleep(3)
#通过id定位元素
# a=driver.find_element(By.ID,"chat-textarea").send_keys("selenium")
# time.sleep(3)



#通过属性值定位,使用send_keys键入信息
# driver.find_element('class name',"chat-input-textarea.chat-input-scroll-style").send_keys("是什么？")
# time.sleep(3)
#使用click点击
# driver.find_element(By.ID,"chat-submit-button").click()
#使用tag_name进行find，返回列表
# element=driver.find_elements(By.TAG_NAME,"a")
# print()
# print(element)
# print(type(element))
# a = driver.find_element("partial link text","片")
# a.click()
# time.sleep(3)
# print(a.text)
# print(type(a))
# print(a.get_attribute("href"))
# b=driver.find_element(By.CSS_SELECTOR, "[href*='baidu']")
# c=b.get_attribute("href")
# print('--------')
# print(c)
#

# from selenium.webdriver.common.by import By
# driver = webdriver.Chrome()
# driver.get("https://www.baidu.com")
# baiduLinks = driver.find_elements(By.CLASS_NAME, "mnav")
# print("找到的链接数量:", len(baiduLinks))
# print("链接文本如下:")
# for link in baiduLinks:
#     # print(link.text)
#     print(link.text, link.get_attribute("href"))